import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class ProxyColor {
  List<String> _items = [];

  List<String> get items => _items;

  void update(String color) {
    List<String> result = [];
    for (var i = 0; i < 20; i++) {
      result.add('$color $i');
    }
    _items = result;
  }

  String getItemAt(int index) {
    return _items[index];
  }
}

class ProxyProviderWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    var count = context.select<ProxyColor, int>((p) => p.items.length);
    return Scaffold(
      appBar: AppBar(title: Text('ProxyProvider')),
      body: ListView.builder(
          itemCount: count, itemBuilder: (context, index) => _Cell(index)),
    );
  }
}

class _Cell extends StatelessWidget {
  final int index;

  _Cell(this.index);

  @override
  Widget build(BuildContext context) {
    var value = context.select<ProxyColor, String>((p) => p.getItemAt(index));
    return ListTile(title: Text(value));
  }
}
